﻿using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.OrcanCommand;
using B.S.Domain.Accounts;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.Management.SteamApplication.CommandHandler.OrcanCommandHandler
{
    public class OrcanDelCommandHandler : IRequestHandler<OrcanDelCommand, APIRequst<int>>
    {
        public OrcanDelCommandHandler(IBaseRepository<OrcanClass> _orcanClassRepository)
        {
            OrcanClassRepository = _orcanClassRepository;
        }

        public IBaseRepository<OrcanClass> OrcanClassRepository { get; }

        public async Task<APIRequst<int>> Handle(OrcanDelCommand request, CancellationToken cancellationToken)
        {
            var path = OrcanClassRepository.GetAll().FirstOrDefault(a => a.OranId == request.Id);
          if(path==null)
            {
                return new APIRequst<int>
                {
                    Code = RequstCode.成功,
                    Msg = "",
                    Data = 0
                };
            }
          else
            {
                path.DeleteName = request.Name;
                path.DeleteTime=DateTime.Now;
                path.isDel=true;
               await OrcanClassRepository.Update(path);
                return new APIRequst<int>
                {
                    Code = RequstCode.成功,
                    Msg = "",
                    Data = 1
                };
            }
        }
    }
}
